#
# 
#
# Authors: Soeren Gebbert, soeren.gebbert@vti.bund.de
#          Axel Don, axel.don@vti.bund.de
#
# Copyright:
#
# Johann Heinrich von Thünen-Institut
# Institut für Agrarrelevante Klimaforschung
#
# Phone: +49 (0)531 596 2601
#
# Fax:+49 (0)531 596 2699
#
# Mail: ak@vti.bund.de
#
# Bundesallee 50
# 38116 Braunschweig
# Germany
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#

library(sp)
library(lattice)

pdf("scamp_t00000.pdf")
# Point positions 
micr_data = read.csv("00000_micr.csv")
carb_data = read.csv("00000_carb.csv")
prof_data = read.csv("00000_prof.csv")
par(mfrow=c(1,1))
plot(Z~mass, data=micr_data, main="Microorganism mass plotted over depth")
dev.set(dev.next())
par(mfrow=c(1,1))
plot(Z~contacts, data=micr_data, main="Number of microorganism-carbon contacts plotted over depth")
dev.set(dev.next())
par(mfrow=c(1,1))
plot(Z~age, data=carb_data, main="Ages of carbon particles plotted over depth")
dev.set(dev.next())

# Profile

# depth,number_of_c_particles,average_c_age,c_mass,number_of_m_cluster,m_mass,number_of_m_contacts,m_mean_radius
par(mfrow=c(3,1))
plot(depth~number_of_c_particles, data=prof_data, type="b", main="Number of carbon particles plotted over depth")
plot(depth~average_c_age, data=prof_data, type="b", main="The average age of carbon particles plotted over depth")
plot(depth~c_mass, data=prof_data, type="b", main="The mass of carbon particles plotted over depth")
dev.set(dev.next())

par(mfrow=c(2,1))
plot(depth~number_of_m_cluster, data=prof_data, type="b", main="Number of microorganism cluster plotted over depth")
plot(depth~number_of_m_contacts, data=prof_data, type="b", main="Number of carbon particle contacts plotted over depth")
dev.set(dev.next())

par(mfrow=c(2,1))
plot(depth~m_mass, data=prof_data, type="b", main="Mass of microorganism cluster plotted over depth")
plot(depth~m_mean_radius, data=prof_data, type="b", main="Mean radius of microorganism cluster plotted over depth")
dev.set(dev.next())

# Spatial data
trellis.par.set(sp.theme()) # sets color ramp to bpy.colors()
par(mfrow=c(1,1))
coordinates(micr_data) <- ~X+Z
coordinates(carb_data) <- ~X+Z
spplot(micr_data, zcol="mass", do.log = TRUE,
	scales=list(draw=T), main="Micro-organism Mass")
spplot(micr_data, zcol="radius", do.log = TRUE,
	scales=list(draw=T), main="Micro-organism Radius")
dev.set(dev.next())
spplot(micr_data, zcol="contacts",
	scales=list(draw=T), main="Micro-organism Contacts")
dev.set(dev.next())
spplot(carb_data, zcol="age",
	scales=list(draw=T), main="Carbon ages")
dev.set(dev.next())
